package com.igeek.boot.config;


import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @package com.igeek.boot.config
 * @Description 阿里沙箱支付配置
 * @Author LittlePunk [296526219@qq.ccom]
 * @Version 2022.1
 * @Date 2024/1/26 21:33
 */
@Data
@Component
@ConfigurationProperties(prefix = "alipay")
public class AliPayConfig {

    //@Value("${alipay.appId}")
    private String appId;
    //@Value("${alipay.appPrivateKey}")
    private String appPrivateKey;
    //@Value("${alipay.alipayPublicKey}")
    private String alipayPublicKey;
    //@Value("${alipay.notifyUrl}")
    private String notifyUrl;


    @PostConstruct
    public void init() {
        // 设置参数（全局只需设置一次）
        Config config = new Config();
        config.protocol = "https";
        config.gatewayHost = "openapi-sandbox.dl.alipaydev.com";
        config.signType = "RSA2";
        config.appId = this.appId;
        System.out.println("config.appId = " + config.appId);
        config.merchantPrivateKey = this.appPrivateKey;
        System.out.println("config.merchantPrivateKey = " + config.merchantPrivateKey);
        config.alipayPublicKey = this.alipayPublicKey;
        System.out.println("config.alipayPublicKey = " + config.alipayPublicKey);
        config.notifyUrl = this.notifyUrl;
        Factory.setOptions(config);
        System.out.println("=======支付宝SDK初始化成功=======");
    }

}

